package com.rogchen.learning.hystrixdemo;

import org.apache.commons.lang.math.RandomUtils;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

@SpringBootApplication
@EnableDiscoveryClient
@Controller
public class HystrixServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(HystrixServerApplication.class, args);
    }


    @RequestMapping("server")
    @ResponseBody
    public Map testIndex() {
        System.out.println("index");
        Map map = new HashMap();
        map.put("abc", 1234);
        System.out.println("b进来了请求");
        boolean b = RandomUtils.nextBoolean();
//        if (b) {
        try {
            TimeUnit.SECONDS.sleep(9);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
//        }
        return map;
//        throw new RuntimeException("就是要异常");
    }
}
